package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.common.util.Assert;
import com.atguigu.srb.common.result.R;
import com.atguigu.srb.common.result.ResponseEnum;
import com.atguigu.srb.core.pojo.entity.IntegralGrade;
import com.atguigu.srb.core.service.IntegralGradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * <p>
 * 积分等级表 前端控制器
 * </p>
 *
 * @author fan
 * @since 2021-11-22
 */
@Slf4j
@RestController
@RequestMapping("/admin/core/integralGrade")
@Api(tags = "积分等级管理")

public class AdminIntegralGradeController {
    @Autowired

    private IntegralGradeService integralGradeService;
    @GetMapping("/list")
    @ApiOperation("积分等级列表")
//    @CrossOrigin
    public R list(){
        List<IntegralGrade> list = integralGradeService.list();
        if (list==null) {
            Assert.isNull(list, ResponseEnum.ERROR);
        }
//        log.trace("1 级别 trace");
//        log.debug("2 级别 debug");
//        log.info("3 级别 info");
//        log.warn("4 级别 warn");
//        log.error("5 级别 error");

        return R.ok().data("list",list);

    }
    @DeleteMapping("/remove/{id}")
    @ApiOperation("根据id删除")
    public R remove(@PathVariable("id") Long id){
        boolean b = integralGradeService.removeById(id);
        Assert.isTrue(b,ResponseEnum.ERROR);
        return R.ok();
    }
    @PostMapping("/save")
    @ApiOperation("新增积分等级")
    public R save(@RequestBody IntegralGrade integralGrade){
        boolean b = integralGradeService.save(integralGrade);
        Assert.isTrue(b,ResponseEnum.ERROR);
        return R.ok();
    }
    @PutMapping("/update")
    @ApiOperation("更新积分等级")
    public R update(@RequestBody IntegralGrade integralGrade){
        boolean b = integralGradeService.updateById(integralGrade);
        Assert.isTrue(b,ResponseEnum.ERROR);
        return R.ok();
    }
    @GetMapping("/getById/{id}")
    @ApiOperation("根据id查询")
    public R getById(@PathVariable("id") Long id){
        IntegralGrade byId = integralGradeService.getById(id);
        if (byId==null){
        Assert.isNull(byId,ResponseEnum.ERROR);
        }
        return R.ok().data("byId",byId);
    }
}

